package guiCode;

import java.sql.SQLException;

import com.sun.rowset.CachedRowSetImpl;

import flexibility.userData;
import basic.ClientConsole;

public class viewRequestCode {
	
	private userData userInfo = new userData();
	private ClientConsole startConnection;
	private CachedRowSetImpl crs;
	
	public viewRequestCode(ClientConsole conn) {
		super();
		
		try {
			crs = new CachedRowSetImpl();
		} catch (SQLException e) {
		
			e.printStackTrace();
		}
		setConnection(conn);
	
	}
	public void setConnection(ClientConsole conn){
		this.startConnection=conn;
		
	}
	public  CachedRowSetImpl getAllRequestsFromDB(){
		userInfo.deleteAll();// reset user info
		userInfo.addData(80);
		userInfo.addData(1);
		startConnection.acceptMsg(userInfo);
		return crs=startConnection.getResults();
	}
	
	/**
	 * set DB to to current status selected.
	 * @param currentTableRequest 
	 * @param approveStatus 1 for Approves status , 0 for Deny status, 2 Not been nor approved nod deny
	 */
	public void setRequestStatus(int currentTableRequest, int approveStatus) {
		//System.out.print(currentTableRequest+" currentTableRequest\n");
		try {
			
		crs.beforeFirst();	////return to the header of  table
		for(int i=0;i<=currentTableRequest;i++)//set the crs to the currentTableRequest row!
		{
			crs.next();
			
		}
		//System.out.print(currentTableRequest+" after For\n");
		userInfo.deleteAll();// reset user info
		userInfo.addData(81);
		userInfo.addData(0);
		userInfo.addData(approveStatus);
		userInfo.addData(crs.getString("requestID"));
		startConnection.acceptMsg(userInfo);
		
		crs.beforeFirst();					//return to the header of  table
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
	

		
	}
	
	
}

	

